<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="audio">操控音频</button>
    <button id="play">播放</button>
    <button id="pause">暂停</button>
    <audio id="media" controls loop="2" muted="muted">
      <source src="./sources/Itsok.mp3" type="audio/mp3" />
      <source src="./sources/Itsok.ogg" type="audio/ogg" />
      <source src="./sources/Itsok.webm" type="audio/webm" />
    </audio>
  </body>
  <script>
    var audio = document.querySelector("#audio"),
      media = document.querySelector("#media");
    audio.onclick = function () {
      console.log(media.buffered.length);
      console.log(media.buffered.start(0));
      // 获取当前音频的URL
      console.log(media.currentSrc);
      // 获取当前音频的播放时间
      console.log(media.currentTime);
      // 判断当前音频是否结束
      console.log(media.ended);
      // 返回音频总时长
      console.log(media.duration);
      // 获取音频的网络状态
      console.log(media.networkState);
      // 获取是否处于暂停状态
      console.log(media.paused);

      console.log(media.canPlayType("audio/mp3")); //返回"probable"：浏览器最可能支持该类型
    };
    // 播放
    document.getElementById("play").onclick = function () {
      media.play();
    };
    // 暂停
    document.getElementById("pause").onclick = function () {
      media.pause();
    };
  </script>
</html>
